<template>
  <div
    class="buttonsContainer"
    :style="{
      paddingBottom: tempData.paddingBottom + 'px',
      paddingLeft: tempData.paddingTwice + 'px',
      paddingRight: tempData.paddingTwice + 'px',
      paddingTop: tempData.paddingTop + 'px',
      boxSizing: 'border-box',
    }"
  >
    <div
      class="btnsContent"
      ref="divDomBtn"
      :style="{
        borderTopLeftRadius: tempData.radiusNumTop + 'px',
        borderTopRightRadius: tempData.radiusNumTop + 'px',
        borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
        borderBottomRightRadius: tempData.radiusNumBottom + 'px',
        background: tempData.bgColor,
      }"
      v-if="tempData.btnType == 'dot' && tempData.items > 1"
    >
      <div class="buttons" v-for="(item, index) in btnList" :key="index" v-show="item.status == 0">
        <div
          class="tags"
          v-show="item.tag"
          :style="{ background: item.tagBg, color: item.tagColor }"
        >
          {{ item.tagText }}
        </div>
        <span class="items">
          <img :src="item.img" alt="" />
          <p class="texts">{{ item.name }}</p>
        </span>
      </div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
    </div>
    <div
      class="btnsContents"
      ref="divDomBtn"
      :style="{
        borderTopLeftRadius: tempData.radiusNumTop + 'px',
        borderTopRightRadius: tempData.radiusNumTop + 'px',
        borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
        borderBottomRightRadius: tempData.radiusNumBottom + 'px',
        background: tempData.bgColor,
      }"
      v-if="tempData.btnType == 'line' && tempData.jiaohu == 'hebing' && tempData.items > 1"
    >
      <div class="buttons" v-for="(item, index) in btnList" :key="index" v-show="item.status == 0">
        <div class="iconBox" style="display: flex; justify-content: center; align-items: center">
          <img style="width: 35px; height: 35px" :src="item.img" alt="" />
          <p style="font-size: 15px; margin-left: 6px; text-align: center" class="texts">{{
            item.name
          }}</p>
        </div>
      </div>
      <div class="lines"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
    </div>
    <div
      class="btnsContents2"
      ref="divDomBtn"
      :style="{
        borderTopLeftRadius: tempData.radiusNumTop + 'px',
        borderTopRightRadius: tempData.radiusNumTop + 'px',
        borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
        borderBottomRightRadius: tempData.radiusNumBottom + 'px',
      }"
      v-if="tempData.btnType == 'line' && tempData.jiaohu == 'fenkai' && tempData.items > 1"
    >
      <div
        class="buttons"
        v-for="(item, index) in btnList"
        :key="index"
        :style="{
          marginBottom: btnList.length > 2 ? '10px' : '0px',
          width: 'calc((100% - ' + (tempData.items - 1) * 10 + 'px) /' + tempData.items + ')',
        }"
        v-show="item.status == 0"
      >
        <div class="iconBox" style="display: flex; justify-content: center; align-items: center">
          <img style="width: 35px; height: 35px" :src="item.img" alt="" />
          <p style="font-size: 15px; margin-left: 6px; text-align: center" class="texts">{{
            item.name
          }}</p>
        </div>
      </div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
      <div style="width: 20%; height: 0px"></div>
    </div>
    <div
      class="btnsContents3"
      ref="divDomBtn"
      :style="{
        borderTopLeftRadius: tempData.radiusNumTop + 'px',
        borderTopRightRadius: tempData.radiusNumTop + 'px',
        borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
        borderBottomRightRadius: tempData.radiusNumBottom + 'px',
      }"
      v-if="tempData.items == 1"
    >
      <div class="buttons" v-for="(item, index) in btnList" :key="index" v-show="item.status == 0">
        <div class="iconBox" style="display: flex; justify-content: center; align-items: center">
          <img style="width: 35px; height: 35px" :src="item.img" alt="" />
          <p style="font-size: 15px; margin-left: 6px; text-align: center" class="texts">{{
            item.name
          }}</p>
        </div>
        <icon-right style="font-size: 24px" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import { watch, ref, onMounted } from 'vue'
  const props = defineProps({
    // 选中的当前组件参数
    compObj: {
      type: Object,
      default: () => {
        return {}
      },
    },
  })
  const divDomBtn: any = ref(null)
  const tempData: any = ref({})
  const btnList: any = ref([])
  const btnWidth = ref('')
  const items = ref()
  watch(
    () => props.compObj,
    (newVal, oldVal) => {
      tempData.value = JSON.parse(JSON.stringify(newVal))
      btnList.value = tempData.value.btnList
      if (items.value) {
        btnWidth.value = items.value / tempData.value.items + 'px'
        console.log(items.value)
      }
      // return a
    },
    { immediate: true, deep: true }
  )

  onMounted(() => {
    items.value = divDomBtn.value.offsetWidth - 40
    btnWidth.value = items.value / tempData.value.items + 'px'
  })
</script>

<style scoped lang="less">
  .buttonsContainer {
    width: 100%;

    .btnsContent {
      background-color: #fff;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      padding: 20px 15px 0px 15px;
      box-sizing: border-box;

      .buttons {
        width: v-bind(btnWidth);
        margin-bottom: 18px;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }

    .btnsContents3 {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      box-sizing: border-box;
      position: relative;

      .lines {
        width: 1px;
        height: 32px;
        background: #e9e9e9;
        position: absolute;
        left: 50%;
        top: 17px;
      }
      .buttons:last-child {
        margin-bottom: 0px;
      }
      .buttons {
        padding: 15px 10px;
        margin-bottom: 10px;
        box-sizing: border-box;
        border-radius: 10px;
        background-color: #fff;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }

    .btnsContents2 {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;

      box-sizing: border-box;
      position: relative;

      .lines {
        width: 1px;
        height: 32px;
        background: #e9e9e9;
        position: absolute;
        left: 50%;
        top: 17px;
      }

      .buttons {
        padding: 15px 0px;
        box-sizing: border-box;
        border-radius: 10px;
        background-color: #fff;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }

    .btnsContents {
      background-color: #fff;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      padding: 15px 15px 15px 15px;
      box-sizing: border-box;
      position: relative;

      .lines {
        width: 1px;
        height: 32px;
        background: #e9e9e9;
        position: absolute;
        left: 50%;
        top: 17px;
      }

      .buttons {
        width: v-bind(btnWidth);
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }
  }
</style>
